package com.leadership.entity.project;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;
import com.demo2do.core.format.PersistentFormat;
import com.leadership.entity.idm.Organization;

/**
 * 
 * @author sjh
 *
 */
@Entity
@Table(name = "project")
public class LdProject {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	/**
	 * 项目名称
	 */
	private String name;
	
	/**
	 * 创建人
	 */
	private Long operator;
	
	/** 状态 */
    @Enumerated(EnumType.STRING)
    private ProjectAuthStatus status;
	

	/**
	 * 自我察觉（90度前测）开始时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date heartMethodStartDate;

	/**
	 * 自我察觉（90度前测）结束时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date heartMethodEndDate;


	/**
	   *  燎原面授课程开始时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date mapStartDate;

	/**
	   * 燎原面授课程结束时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date mapEndDate;

	
	/**
	  * 燎原在线课程 开始时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date courseStartDate;
	
	/**
	 * 燎原在线课程 结束时间
	*/
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date courseEndDate;

	
	/**
	 * 燎原刻意练习开始时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date exerciseStartDate;
	
	/**
               * 燎原刻意练习结束时间
     */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date exerciseEndDate;
	
	
	/**
	 * 非人1.0认证开始时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date certificateStartDate;
	
	/**
               * 非人1.0认证结束时间
     */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date certificateEndDate;

	/**
	 * 360度评估开始时间
	 */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date evaluationStartDate;
	
	/**
     * 360度评估结束时间
     */
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Type(type = "date")
	private Date evaluationEndDate;
	
	/**
	 * 创建时间
	 */
	private Date createTime;
	
	/** 部门 ID */
    @ManyToOne(fetch = FetchType.EAGER, optional = true)
    @PersistentFormat
    private Organization organization;
	
	@Column(name = "is_disabled")
	private boolean disabled;
	
	

	/**
	 * the defauld constructor
	 */
	public LdProject() {
		
	}
	
	public LdProject(String projectName, Organization organization, Long loginId, 
	                 Date heartMethodStartDate, Date heartMethodEndDate,
	                 Date mapStartDate, Date mapEndDate,
	                 Date courseStartDate, Date courseEndDate,
	                 Date exerciseStartDate, Date exerciseEndDate,
	                 Date certificateStartDate, Date certificateEndDate,
	                 Date evaluationStartDate, Date evaluationEndDate) {
	    this.name = projectName;
	    this.organization = organization;
	    this.heartMethodEndDate = heartMethodEndDate;
	    this.heartMethodStartDate = heartMethodStartDate;
	    this.mapEndDate = mapEndDate;
	    this.mapStartDate = mapStartDate;
	    this.courseEndDate = courseEndDate;
	    this.courseStartDate = courseStartDate;
	    this.exerciseEndDate = exerciseEndDate;
	    this.exerciseStartDate = exerciseStartDate;
	    this.certificateEndDate = certificateEndDate;
	    this.certificateStartDate = certificateStartDate;
	    this.evaluationEndDate = evaluationEndDate;
	    this.evaluationStartDate = evaluationStartDate;
	    this.operator = loginId;
	    this.status = ProjectAuthStatus.AUDITED;
	    this.disabled = false;
	}
	
	/**
	 * 
	 * @param operator
	 * @return
	 */
	public LdProject initilization(Long operator) {
		this.disabled = false;
		this.operator = operator;
		this.createTime = new Date();
		
		return this;
		
	}
	
	/**
     * 
     * @param operator
     * @return
     */
    public LdProject initilization(Long operator, ProjectAuthStatus status) {
        this.disabled = false;
        this.operator = operator;
        this.createTime = new Date();
        this.status = status;
        
        return this;
        
    }
	
	/**
	 * 
	 * @param projectName
	 * @param operator
	 * @return
	 */
    public LdProject initilization(String projectName, Long operator) {
        this.name = projectName;
        this.disabled = false;
        this.operator = operator;
        this.createTime = new Date();
        
        return this;
        
    }

	/**
	 * 
	 * @param name
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public LdProject editDate(String name, Date startDate, Date endDate){
	    if(StringUtils.equals(name, "heart-method")) {
	        this.heartMethodStartDate = startDate;
	        this.heartMethodEndDate = endDate;
	    } else if(StringUtils.equals(name, "map")) {
	        this.mapStartDate = startDate;
	        this.mapEndDate = endDate;
	    } else if(StringUtils.equals(name, "course")) {
            this.courseStartDate = startDate;
            this.courseEndDate = endDate;
        } else if(StringUtils.equals(name, "exercise")) {
            this.exerciseStartDate = startDate;
            this.exerciseEndDate = endDate;
        } else if(StringUtils.equals(name, "certificate")) {
            this.certificateStartDate = startDate;
            this.certificateEndDate = endDate;
        } else if(StringUtils.equals(name, "evaluation")) {
            this.evaluationStartDate = startDate;
            this.evaluationEndDate = endDate;
        }
	    return this;
	}
	
	/**
	 * 
	 * @param name
	 * @return
	 */
	public LdProject editName(String name) {
	    this.name = name;
	    return this;
	}
	
	public LdProject changeOperator(Long operator) {
        this.operator = operator;
        return this;
    }
	
	/**
	 * 
	 * @param status
	 * @return
	 */
	public LdProject changeStatus(ProjectAuthStatus status) {
	    this.status = status;
	    return this;
	}
	
	/**
	 * 
	 * @return
	 */
	public Date getPlanStartDate() {
		Date startDate = this.mapStartDate.before(this.courseStartDate) ? mapStartDate : courseStartDate;
		startDate = startDate.before(this.exerciseStartDate) ? startDate : exerciseStartDate; 
		return startDate;
	}
	
	/**
	 * 
	 * @return
	 */
	public Date getPlanEndDate() {
		Date endDate = this.mapEndDate.after(this.courseEndDate) ? mapEndDate : courseEndDate;
		endDate = endDate.after(this.exerciseEndDate) ? endDate : exerciseEndDate; 
		return endDate;
	}

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the operator
     */
    public Long getOperator() {
        return operator;
    }

    /**
     * @return the status
     */
    public ProjectAuthStatus getStatus() {
        return status;
    }

    /**
     * @return the heartMethodStartDate
     */
    public Date getHeartMethodStartDate() {
        return heartMethodStartDate;
    }

    /**
     * @return the heartMethodEndDate
     */
    public Date getHeartMethodEndDate() {
        return heartMethodEndDate;
    }

    /**
     * @return the mapStartDate
     */
    public Date getMapStartDate() {
        return mapStartDate;
    }

    /**
     * @return the mapEndDate
     */
    public Date getMapEndDate() {
        return mapEndDate;
    }

    /**
     * @return the courseStartDate
     */
    public Date getCourseStartDate() {
        return courseStartDate;
    }

    /**
     * @return the courseEndDate
     */
    public Date getCourseEndDate() {
        return courseEndDate;
    }

    /**
     * @return the exerciseStartDate
     */
    public Date getExerciseStartDate() {
        return exerciseStartDate;
    }

    /**
     * @return the exerciseEndDate
     */
    public Date getExerciseEndDate() {
        return exerciseEndDate;
    }

    /**
     * @return the certificateStartDate
     */
    public Date getCertificateStartDate() {
        return certificateStartDate;
    }

    /**
     * @return the certificateEndDate
     */
    public Date getCertificateEndDate() {
        return certificateEndDate;
    }

    /**
     * @return the evaluationStartDate
     */
    public Date getEvaluationStartDate() {
        return evaluationStartDate;
    }

    /**
     * @return the evaluationEndDate
     */
    public Date getEvaluationEndDate() {
        return evaluationEndDate;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the organization
     */
    public Organization getOrganization() {
        return organization;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param operator the operator to set
     */
    public void setOperator(Long operator) {
        this.operator = operator;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(ProjectAuthStatus status) {
        this.status = status;
    }

    /**
     * @param heartMethodStartDate the heartMethodStartDate to set
     */
    public void setHeartMethodStartDate(Date heartMethodStartDate) {
        this.heartMethodStartDate = heartMethodStartDate;
    }

    /**
     * @param heartMethodEndDate the heartMethodEndDate to set
     */
    public void setHeartMethodEndDate(Date heartMethodEndDate) {
        this.heartMethodEndDate = heartMethodEndDate;
    }

    /**
     * @param mapStartDate the mapStartDate to set
     */
    public void setMapStartDate(Date mapStartDate) {
        this.mapStartDate = mapStartDate;
    }

    /**
     * @param mapEndDate the mapEndDate to set
     */
    public void setMapEndDate(Date mapEndDate) {
        this.mapEndDate = mapEndDate;
    }

    /**
     * @param courseStartDate the courseStartDate to set
     */
    public void setCourseStartDate(Date courseStartDate) {
        this.courseStartDate = courseStartDate;
    }

    /**
     * @param courseEndDate the courseEndDate to set
     */
    public void setCourseEndDate(Date courseEndDate) {
        this.courseEndDate = courseEndDate;
    }

    /**
     * @param exerciseStartDate the exerciseStartDate to set
     */
    public void setExerciseStartDate(Date exerciseStartDate) {
        this.exerciseStartDate = exerciseStartDate;
    }

    /**
     * @param exerciseEndDate the exerciseEndDate to set
     */
    public void setExerciseEndDate(Date exerciseEndDate) {
        this.exerciseEndDate = exerciseEndDate;
    }

    /**
     * @param certificateStartDate the certificateStartDate to set
     */
    public void setCertificateStartDate(Date certificateStartDate) {
        this.certificateStartDate = certificateStartDate;
    }

    /**
     * @param certificateEndDate the certificateEndDate to set
     */
    public void setCertificateEndDate(Date certificateEndDate) {
        this.certificateEndDate = certificateEndDate;
    }

    /**
     * @param evaluationStartDate the evaluationStartDate to set
     */
    public void setEvaluationStartDate(Date evaluationStartDate) {
        this.evaluationStartDate = evaluationStartDate;
    }

    /**
     * @param evaluationEndDate the evaluationEndDate to set
     */
    public void setEvaluationEndDate(Date evaluationEndDate) {
        this.evaluationEndDate = evaluationEndDate;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param organization the organization to set
     */
    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
